package com.llbnk.springcoding.controller;

import com.llbnk.springcoding.pojo.TestInform;
import com.llbnk.springcoding.service.BlockService;
import com.llbnk.springcoding.service.TestService;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    private BlockService blockService;

    @GetMapping("/get/fill/inform")
    public String getInform(@RequestParam("name") String name) throws JSONException {
        TestInform inform = testService.getInform(name);
        return inform.toString();
    }

    @GetMapping("/test/async/block")
    public String testAsyncBlock() {
        blockService.testAsyncBlock();
        return "success";
    }

    @GetMapping("/test/async/future")
    public List<Integer> testAsyncFuture(@RequestParam("numbers") List<Integer> numbers) {
        return blockService.testAsyncFuture(numbers);
    }

    @GetMapping("/test/red/lock")
    public String testAnnotationRedLock(@RequestParam("userId") Integer userId) {
        return blockService.testAnnotationRedLock(userId);
    }

}